<?php

/**
 * Category
 *  
 * @author james
 * @version 
 */

require_once 'Zend/Db/Table/Abstract.php';

class Category extends Zend_Db_Table_Abstract {
	/**
	 * The default table name 
	 */
	protected $_name = 'category';
	protected $_primary = 'id';
	
	protected $dependentTables = array(
		'Inivitation',
		'ThemeCategoryMap'
	);
	

	/**
	 * Find category by id.
	 * 
	 * @param $id theme id
	 */
	public function findById($id) {
		return $this->find($id)->current();
	}
	
	/**
	 * Find all available category.
	 * 
	 * @return return available category:
	 */
	public static function findAllAvailableCategory() {
		$category = new Category();
		$categories = array();
		$select = $category->select();
		
		$select->from($category->_name, array('id', 'name'));
		return $category->fetchAll($select);
	}
	
	/**
	 * Find themes by given category.
	 * 
	 * @param $category_id category id
	 */
	public static function findThemesByCategory($category_id) {
		$category = new Category();
		$category = $category->find($category_id)->current();
		return $category->findManyToManyRowset('Theme', 'ThemeCategoryMap');
	}

}

